<?php
define('BASE_URL', 'http://marketeronline.site11.com/index.php');
define('SIGN_UP_URL', BASE_URL.'?a=signup');

function getImage($output) {
	if (preg_match_all('/<img[^>][^>]*src\=\"([^\"]*)\"[^>]*>/s', $output , $captchaimages)) {
		$captcha = $captchaimages[1][0]; //this returns image url with amp;
		$captcha = str_replace("amp;","",$captcha); //remove amp; from the string
		echo '<img src='.BASE_URL.$captcha.'>';
	}
}

// Debug
function debug($data){
	echo '<pre>';
	print_r($data);
	echo '</pre>';
}

/* STEP 1. let’s create a cookie file */
$ckfile = tempnam("tmp", "CURLCOOKIE");

/* STEP 2. visit the homepage to set the cookie properly */
if (empty($_POST)) {
	$ch = curl_init(SIGN_UP_URL);
	curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
	$output = curl_exec($ch);
	curl_close($ch);
	getImage($output);
}

if (!empty($_POST)) {
	/* STEP 3. visit cookiepage.php */
	$name = 'acc_'.uniqid();
	$email = 'acc_'.uniqid().'@yahoo.com';
	$data = array(
		'a' => 'signup',
		'action' => 'signup',
		'fullname' => $name,
		'username' => $name,
		'password' => '123456',
		'password2' => '123456',
		'email' => $email,
		'email1' => $email,
		'sq' => uniqid(),
		'sa' => uniqid(),
		'agree' => 1,
		'validation_number' => $_POST['validation_number']
	);
	
	//url-ify the data for the POST
	$dataString = '';
	foreach($data as $key=>$value) {
		$dataString .= $key.'='.$value.'&';
	}
	rtrim($dataString,'&');
	
	$ch = curl_init(SIGN_UP_URL);
	curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch,CURLOPT_POST, count($data));
	curl_setopt($ch,CURLOPT_POSTFIELDS, $dataString);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	
	$output = curl_exec($ch);
	curl_close($ch);
	getImage($output);
}
?>
<form method="post" action="" name="regform">
	<input type="text" name="validation_number" class="inpts" size="15">
	<input type="submit" value="Register" class="sbmt">
</form>